/*
day243
2020.4.27
*/ 
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {
		vector<TreeNode*> res;
		res.push_back(root);
		
		for(const int &tem : to_delete)
		{
			TreeNode *cur_Node=nullptr;
			for(int i=0;i<res.size();++i)
			{
				if(res[i]==tem) 
				{
					res.emplace() 
				}
				cur_Node=find(res[i],tem);
				if(cur_Node)
				{
					break;
				}
			}
			if(cur_Node)
			{
				TreeNode *target=nullptr;
				if(cur_Node->left && cur_Node->left->val==tem)
				{
					target=cur_Node->left;
					cur_Node->left=nullptr;
				}
				else
				{
					target=cur_Node->right;
					cur_Node->right=nullptr;
				}
				
				if(target->left)
				{
					res.push_back(target->left);
				}
				if(target->right)
				{
					res.push_back(target->right);
				}
			}
		}
		return res;
    }
    
    TreeNode *find(TreeNode *root,int val)
    {
    	if( !root || (!root->left && !root->right) )
    	{
    		return nullptr;
		}
		
		if(root->left && root->left->val==val || root->right && root->right->val==val)
		{
			return root;
		}
		
		TreeNode *l=find(root->left,val); 
		TreeNode *r=find(root->right,val);
		
		return l ? l : r;
	}
};



int main()
{
	return 0;
 } 
